package com.woniuxy.kaer.system.controller;


import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.system.annotation.RequirePermission;
import com.woniuxy.kaer.system.annotation.RequireRole;
import com.woniuxy.kaer.system.model.Role;
import com.woniuxy.kaer.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sun
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色管理")
public class RoleController {
    @Resource
    private RoleService roleService;
    @Resource
    private JwtUtil jwtUtil;

    //新增角色
    @ApiOperation("新增角色")
    @PostMapping("addRole")
    @RequireRole("BOSS")
    @RequirePermission("新增角色")
    public Result addRole(@RequestParam("roleName") String roleName) throws Exception {

        // 调用服务层进行保存
        roleService.addRole(roleName);

        return Result.succeed("新增角色成功", null);
    }
    //查询所有角色
    @ApiOperation("查询所有角色")
    @PostMapping("/findAllRole")
    @RequirePermission("查询所有角色")
    @RequireRole("BOSS")
    public Result findAllRole() throws Exception {
        roleService.findAllRole();
        return Result.succeed("查询所有角色成功", roleService.list());
    }

    //查询自身的角色
    @ApiOperation("查询自身的角色")
    @PostMapping("/getOurRole")
    @RequirePermission("/role/getOurRole查询自身的角色")
    public Result getOurRole(@RequestHeader("token") String token) throws Exception {
        Integer managerId1 = jwtUtil.getManagerId1(token);
        Role role = roleService.getById(managerId1);
        return Result.succeed("查询自身的角色成功",role);
    }

    //根据角色id查找角色
    @ApiOperation("根据角色id查找角色")
    @PostMapping("/findRoleById")
    @RequirePermission("/role/findRoleById根据角色ID查询角色")
    public Result findRoleById(@RequestParam("roleId") Integer roleId) throws Exception {
        Role role = roleService.getById(roleId);
        return Result.succeed("查询角色成功",role);
    }

    //


}

